<extend name="Layout/ins_page" />
<block name="content">
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Form</title>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
        <link href="/sap/demo.css" rel="stylesheet" type="text/css" />
        <script src="/sap/scripts/boot.js" type="text/javascript"></script>
    </head>
    <style>

        td{
            margin-top:10px;

        }
    </style>
    <body>
    <div id="form1" >
        <input name="id" class="mini-hidden"  value="{$data.item_id}"/>
        <input name="attachmentID" class="mini-hidden"  value="{$data.attachmentID}"/>
        <table cellspacing='10' style="width: 700px; border-spacing:0px 10px;" >

            <tr>
                <td>
                    <label for="textbox1$text">物料名称：</label>
                </td>
                <td>
                    <input id="item_name"  name="item_name" class="mini-textbox" readonly width='250px' value ="{$data.item_name}"/>
                    <!--(建议命名规则:品牌+物料+型号)-->
                </td>
            </tr>

            <tr>
                <td>
                    <label for="textbox1$text">品牌：</label>
                </td>
                <td>
                    <input onvaluechanged="checkAndMergeString(this)" required="true"  label="ComboBox："   id="brand-select" class="mini-buttonedit" onbuttonclick="onButtonEdit2"   value="{$data.brand_id}" text="{$data.brand_name}" name="" textName="" style="width: 250px"/><-在这里选取
                </td>
            </tr>

            <tr>
                <td>
                    <label for="textbox1$text">物料简名：</label>
                </td>
                <td>
                    <input onvaluechanged="checkAndMergeString(this)" id="item_short_name"  name="item_short_name" class="mini-textbox" required="true" width='250px' value ="{$data.item_short_name}"/>
                </td>
            </tr>

            <tr>
                <td>
                    <label for="textbox1$text">型号：</label>
                </td>
                <td>
                    <input onvaluechanged="checkAndMergeString(this)" id="model"  name="model" class="mini-textbox" required="false" width='250px'  value ="{$data.model}"/>
                </td>
            </tr>

            <tr>
                <td>
                    <label for="textbox1$text">规格：</label>
                </td>
                <td>
                    <input onvaluechanged="checkAndMergeString(this)" id="specifications"  name="specifications" class="mini-textbox" required="false" width='250px'  value ="{$data.specifications}"/>
                </td>
            </tr>

            <tr>
                <td>
                    <label for="textbox1$text">颜色：</label>
                </td>
                <td>
                    <input onvaluechanged="checkAndMergeString(this)" id="color"  name="color" class="mini-textbox" required="false" width='250px'  value ="{$data.color}"/>
                </td>
            </tr>

            <tr>
                <td>
                    <label for="textbox1$text">物料图：</label>
                </td>
                <td>
	<div id='showimg'>
             		<?php $imglist = explode(',',$data['logo']);
             		foreach($imglist as $key=> $voimg){
					   if($voimg){
						echo "[<img id='simg' class='group-picture' width='100px' height='100px' src='$voimg' alt='物料图' >";

        $already = 0;

        foreach($data['imageResult'] as $imageKey => $imageValue){

        if ($imageValue['image_id'] == $key && $imageValue['image_type'] == 1)
        {
            if($imageValue['cancelled'] == 1)
            {
                echo "<span style=\"color: red;font-weight:bold \">已作废</span>";
                $already = 1;
                break;
            }
        }

        }

        if(!$already)
        {
        echo "<a href=javascript:cancelimage($data[item_id],$key,1)>执行作废</a>";
        }

        echo ']';


                }
					}

             		?>
		     	     
		     	    </div>
                    <a href="javascript:;" class="a-upload" onclick="$('#group-picture1').click()" > 选择 </a>
                    <input type="file" id='group-picture1' name="group-picture" id="group-picture1" style="display: none;" multiple="true">
                    <input  name="logo" id='logo-input' class="mini-textbox" required="false" width='250px'  value ="{$data.logo}" style="display: none""/>


                </td>
            </tr>

            <tr>
                <td>
                    <label for="textbox1$text">物料详情图：</label>
                </td>
                <td>
                    <div id='showimgB'>
                        <?php $imglist = explode(',',$data['detail_image']);
             		foreach($imglist as $key=> $voimg){
					   if($voimg)
					   {
					        echo "[<img id='simg' class='group-picture' width='100px' height='100px' src='$voimg' alt='物料详情图' >";

                        $already = 0;

                        foreach($data['imageResult'] as $imageKey => $imageValue){

                        if ($imageValue['image_id'] == $key && $imageValue['image_type'] == 2)
                        {
                        if($imageValue['cancelled'] == 1)
                        {
                        echo "<span style=\"color: red;font-weight:bold \">已作废</span>";
                        $already = 1;
                        break;
                        }
                        }

                        }

                        if(!$already)
                        {
                        echo "<a href=javascript:cancelimage($data[item_id],$key,2)>执行作废</a>";
                        }

                        echo ']';

                            }

                                    }

                        ?>

                    </div>
                    <a href="javascript:;" class="a-upload" onclick="$('#group-picture2').click()" > 上传图片</a>(使用ctrl键可多选上传)
                    <input type="file" id='group-picture2' name="group-picture2" id="group-picture2" style="display: none; "  multiple="true">
                    <input  name="detail_image" id='detail_image-input' class="mini-textbox" required="false" width='250px'  value ="{$data.detail_image}" style="display: none""/>


                </td>
            </tr>

            <tr>
                <td>
                    <label for="textbox1$text">品类(*必填)：</label>
                </td>
                <td>

                    <ul id="tree1" class="mini-tree" url="/SapSupplier/getitemcategorycode" style="width:200px;padding:5px;"
                        showTreeIcon="true" textField="text" idField="id" parentField="pid" resultAsTree="false"
                        onbeforenodeselect="onBeforeNodeSelect"
                        showRadioButton="true" showFolderCheckBox="false" expandOnLoad="false">
                    </ul>
                    <!--/Public/data/listTree.txt-->

                </td>
            </tr>


            <tr>
                <td>
                    <label for="textbox1$text">重量：</label>
                </td>
                <td>
                    <input required="true" name="weight" class="mini-spinner" value="{$data.weight}" minValue="0" maxValue="9999999"  width="250px"/>

                </td>
            </tr>


            <tr>
                <td>
                    <label for="textbox1$text">订货周期：</label>
                </td>
                <td>
                    <input required="true" name="ordering_day" class="mini-spinner" value="{$data.ordering_day}" minValue="0" maxValue="9999999" width="250px" />

                </td>
            </tr>


            <tr>
                <td>
                    <label for="textbox1$text">是否序列号管理：</label>
                </td>
                <td>
                    <input   required="true"  name='is_serial' class="mini-combobox" style="width:250px;" textField="text" valueField="id" data="[{'id':'Y','text':'是'},{'id':'N','text':'否'}]"  value="{$data.is_serial}" />

                </td>
            </tr>


            <tr>
                <td>
                    <label for="textbox1$text">是否为3C：</label>
                </td>
                <td>
                    <input  required="true" readonly id='is_3c' name='is_3c' class="mini-combobox" style="width:250px;" textField="text" valueField="id" data="[{'id':'Y','text':'是'},{'id':'N','text':'否'}]" value="{$data.is_3c}"  />

                </td>
            </tr>

            <tr>
                <td>
                    <label for="textbox1$text">产品经理：</label>
                </td>
                <td>
                    <!--<input id="textbox1"  name="pm" class="mini-textbox" required="false" width='250px'  value ="{$data.pm}"/>-->
                    <input required="true"  id='textbox1'  name="pm" showNullItem="true" class="mini-combobox" url="/stocking/getUser?type=1" valueField="id" textField="text"   value="{$data.pm}" />
                </td>
            </tr>

            <tr>
                <td>
                    <label for="textbox1$text">采购价格：</label>
                </td>
                <td>
                    <input required="true" name="UptodatePurchasePrice" class="mini-spinner" format="c2" value="{$data.UptodatePurchasePrice}" minValue="0" maxValue="9999999" width="250px" />
                </td>
            </tr>

            <tr>
                <td>
                    <label for="textbox1$text">税收编码：</label>
                </td>
                <td>
                    <input required="true" name="tax_code" class="mini-textbox" value="{$data.tax_code}" width="250px" />
                </td>
            </tr>

            <!--物料附加信息 Begin-->

            <!--天猫B-->

            <tr>
                <td>
                    <label for="textbox1$text">天猫链接：</label>
                </td>
                <td>
                    <input id="textbox1"  name="tamll" class="mini-textbox" required="false" width='250px' height="150px"  value ="{$data.tamll}"/>
                </td>
            </tr>

            <tr>
                <td>
                    <label for="textbox1$text">天猫售价：</label>
                </td>
                <td>
                    <input name="tamll_price" class="mini-spinner" format="c2" value="{$data.tamll_price}" minValue="0" maxValue="9999999" width="250px" />
                </td>
            </tr>

            <tr>
                <td>
                    <label for="textbox1$text">天猫销售量：</label>
                </td>
                <td>
                    <input name="tamll_S_AMT" class="mini-spinner" value="{$data.tamll_S_AMT}" minValue="0" maxValue="9999999" width="250px" />
                </td>
            </tr>

            <!--天猫E-->

            <!--京东B-->

            <tr>
                <td>
                    <label for="textbox1$text">京东链接：</label>
                </td>
                <td>
                    <input id="textbox1"  name="jd" class="mini-textbox" required="false" width='250px' height="150px"  value ="{$data.jd}"/>
                </td>
            </tr>

            <tr>
                <td>
                    <label for="textbox1$text">京东售价：</label>
                </td>
                <td>
                    <input name="jd_price" class="mini-spinner" format="c2" value="{$data.jd_price}" minValue="0" maxValue="9999999" width="250px" />
                </td>
            </tr>

            <tr>
                <td>
                    <label for="textbox1$text">京东销售量：</label>
                </td>
                <td>
                    <input name="jd_S_AMT" class="mini-spinner" value="{$data.jd_S_AMT}" minValue="0" maxValue="9999999" width="250px" />
                </td>
            </tr>

            <!--京东E-->

            <!--广发B-->

            <tr>
                <td>
                    <label for="textbox1$text">广发链接：</label>
                </td>
                <td>
                    <input id="textbox1"  name="guangfa" class="mini-textbox" required="false" width='250px' height="150px"  value ="{$data.guangfa}"/>
                </td>
            </tr>

            <tr>
                <td>
                    <label for="textbox1$text">广发售价：</label>
                </td>
                <td>
                    <input name="guangfa_price" class="mini-spinner" format="c2" value="{$data.guangfa_price}" minValue="0" maxValue="9999999" width="250px" />
                </td>
            </tr>

            <tr>
                <td>
                    <label for="textbox1$text">广发销售量：</label>
                </td>
                <td>
                    <input name="guangfa_S_AMT" class="mini-spinner" value="{$data.guangfa_S_AMT}" minValue="0" maxValue="9999999" width="250px" />
                </td>
            </tr>

            <!--广发E-->

            <!--建行B-->

            <tr>
                <td>
                    <label for="textbox1$text">建行链接：</label>
                </td>
                <td>
                    <input id="textbox1"  name="jianhang" class="mini-textbox" required="false" width='250px' height="150px"  value ="{$data.jianhang}"/>
                </td>
            </tr>

            <tr>
                <td>
                    <label for="textbox1$text">建行售价：</label>
                </td>
                <td>
                    <input name="jianhang_price" class="mini-spinner" format="c2" value="{$data.jianhang_price}" minValue="0" maxValue="9999999" width="250px" />
                </td>
            </tr>

            <tr>
                <td>
                    <label for="textbox1$text">建行销售量：</label>
                </td>
                <td>
                    <input name="jianhang_S_AMT" class="mini-spinner" value="{$data.jianhang_S_AMT}" minValue="0" maxValue="9999999" width="250px" />
                </td>
            </tr>

            <!--建行E-->

            <!--招行B-->

            <tr>
                <td>
                    <label for="textbox1$text">招行链接：</label>
                </td>
                <td>
                    <input id="textbox1"  name="zhaohang" class="mini-textbox" required="false" width='250px' height="150px"  value ="{$data.zhaohang}"/>
                </td>
            </tr>

            <tr>
                <td>
                    <label for="textbox1$text">招行售价：</label>
                </td>
                <td>
                    <input name="zhaohang_price" class="mini-spinner" format="c2" value="{$data.zhaohang_price}" minValue="0" maxValue="9999999" width="250px" />
                </td>
            </tr>

            <tr>
                <td>
                    <label for="textbox1$text">招行销售量：</label>
                </td>
                <td>
                    <input name="zhaohang_S_AMT" class="mini-spinner" value="{$data.zhaohang_S_AMT}" minValue="0" maxValue="9999999" width="250px" />
                </td>
            </tr>

            <!--招行E-->

            <!--交行B-->

            <tr>
                <td>
                    <label for="textbox1$text">交行链接：</label>
                </td>
                <td>
                    <input id="textbox1"  name="jiaohang" class="mini-textbox" required="false" width='250px' height="150px"  value ="{$data.jiaohang}"/>
                </td>
            </tr>

            <tr>
                <td>
                    <label for="textbox1$text">交行售价：</label>
                </td>
                <td>
                    <input name="jiaohang_price" class="mini-spinner" format="c2" value="{$data.jiaohang_price}" minValue="0" maxValue="9999999" width="250px" />
                </td>
            </tr>

            <tr>
                <td>
                    <label for="textbox1$text">交行销售量：</label>
                </td>
                <td>
                    <input name="jiaohang_S_AMT" class="mini-spinner" value="{$data.jiaohang_S_AMT}" minValue="0" maxValue="9999999" width="250px" />
                </td>
            </tr>

            <!--交行E-->

            <!--民生B-->

            <tr>
                <td>
                    <label for="textbox1$text">民生链接：</label>
                </td>
                <td>
                    <input id="textbox1"  name="minsheng" class="mini-textbox" required="false" width='250px' height="150px"  value ="{$data.minsheng}"/>
                </td>
            </tr>

            <tr>
                <td>
                    <label for="textbox1$text">民生售价：</label>
                </td>
                <td>
                    <input name="minsheng_price" class="mini-spinner" format="c2" value="{$data.minsheng_price}" minValue="0" maxValue="9999999" width="250px" />
                </td>
            </tr>

            <tr>
                <td>
                    <label for="textbox1$text">民生销售量：</label>
                </td>
                <td>
                    <input name="minsheng_S_AMT" class="mini-spinner" value="{$data.minsheng_S_AMT}" minValue="0" maxValue="9999999" width="250px" />
                </td>
            </tr>

            <!--民生E-->

            <!--平安B-->

            <tr>
                <td>
                    <label for="textbox1$text">平安链接：</label>
                </td>
                <td>
                    <input id="textbox1"  name="pingan" class="mini-textbox" required="false" width='250px' height="150px"  value ="{$data.pingan}"/>
                </td>
            </tr>

            <tr>
                <td>
                    <label for="textbox1$text">平安售价：</label>
                </td>
                <td>
                    <input name="pingan_price" class="mini-spinner" format="c2" value="{$data.pingan_price}" minValue="0" maxValue="9999999" width="250px" />
                </td>
            </tr>

            <tr>
                <td>
                    <label for="textbox1$text">平安销售量：</label>
                </td>
                <td>
                    <input name="pingan_S_AMT" class="mini-spinner" value="{$data.pingan_S_AMT}" minValue="0" maxValue="9999999" width="250px" />
                </td>
            </tr>

            <!--平安E-->

            <!--中信B-->

            <tr>
                <td>
                    <label for="textbox1$text">中信链接：</label>
                </td>
                <td>
                    <input id="textbox1"  name="zhongxin" class="mini-textbox" required="false" width='250px' height="150px"  value ="{$data.zhongxin}"/>
                </td>
            </tr>

            <tr>
                <td>
                    <label for="textbox1$text">中信售价：</label>
                </td>
                <td>
                    <input name="zhongxin_price" class="mini-spinner" format="c2" value="{$data.zhongxin_price}" minValue="0" maxValue="9999999" width="250px" />
                </td>
            </tr>

            <tr>
                <td>
                    <label for="textbox1$text">中信销售量：</label>
                </td>
                <td>
                    <input name="zhongxin_S_AMT" class="mini-spinner" value="{$data.zhongxin_S_AMT}" minValue="0" maxValue="9999999" width="250px" />
                </td>
            </tr>

            <!--中信E-->

            <!--物料附加信息 End-->

            <tr>
                <td>
                    <label for="textbox1$text">备注：</label>
                </td>
                <td>
                    <input id="textbox1"  name="remarkes" class="mini-textbox" required="false" width='250px' height="150px"  value ="{$data.remarkes}"/>
                </td>
            </tr>

            <tr>
                <td>
                    <label for="textbox1$text">物料详情文字版：</label>
                </td>
                <td>
                    <input id="textbox1"  name="details" class="mini-textarea" required="false" width='250px' height="150px"  value ="{$data.details}"/>
                </td>
            </tr>

            <!--<tr>-->
                <!--<td>-->
                    <!--<label for="textbox1$text">物料详情*：</label>-->
                <!--</td>-->
                <!--<td>-->
                    <!--<div class="uploader" id="uploader_add_file" add_file_id="add_file">-->
                        <!--<input id="add_file_add_file" required="true" class="add_file"  name="attachment" value="{$data.attachment}" style="display: none" >-->
                        <!--<a id="btn_add_file" href="javascript:;" class="">添加附件</a>-->
                        <!--<ul class="file_list" new_upload="" >-->

                            <!--<?php foreach($data['att'] as $att){?>-->
                            <!--<li class="tbody" id="{$att.md5}" add_file="{$att.code}">-->
                                <!--<div class="loading" style="width: 100%;"></div>-->
                                <!--<div class="data" >-->
                                    <!--<span class="del text-center" style='width: 75px'>-->
                                        <!--&lt;!&ndash;<a class="link del" style="display: inline;">删除</a> &ndash;&gt;-->
                                        <!--<a class="link showpic" href='/Uploads/Download/{$att.savepath}{$att.savename}' data='/Uploads/Download/{$att.savepath}{$att.savename}'>查看</a></span>-->
                                    <!--<span class="size text-right">{$att.size} kb</span><span class="auto autocut">{$att.name}</span></div>-->
                            <!--</li>-->
                            <!--<?php }?>-->

                        <!--</ul>-->
                    <!--</div>-->
                <!--</td>-->
            <!--</tr>-->

            <!--<tr>-->
                <!--<td>-->
                    <!--<label for="textbox1$text">毛利表：</label>-->
                <!--</td>-->
                <!--<td>-->
                    <!--<if condition=' ($canEdit) '>-->
                        <!--<a class="mini-button" enabled="" id='query-bt' onclick="openaddprofit()">添加毛利表</a>-->
                    <!--<else/>-->
                        <!--<a class="mini-button" enabled="" id='query-bt' onclick="showprofit()">毛利表</a>-->
                    <!--</if>-->
                <!--</td>-->
            <!--</tr>-->

            <tr>
                <td>

                </td>
                <td>

                    <br/>

                    <script type="text/javascript">
                        function openaddprofit() {
                            mini.open({
                                url: "/index.php?m=&c=SapSupplier&a=addprofit&item_id="+<?php echo $_REQUEST['id']; ?>,
                                title: "毛利表",
                                width: 800,
                                height: 380,
                                ondestroy: function (action) {
                                    if (action == "ok") {
                                        var iframe = this.getIFrameEl();
                                        var data = iframe.contentWindow.GetData();
                                        data = mini.clone(data);    //必须
                                        if (data) {
                                            if (checkItems(data.item_id)) {
                                                mini.alert(data.item_name + '已存在列表中');
                                                return;
                                            }
                                            var ndata = [];
                                            ndata.item_name = data.item_name;
                                            ndata.sap_code = data.sap_code;
                                            ndata.logo = data.logo;
                                            ndata.color = data.color;
                                            ndata.weight = data.weight;
                                            grid2.addRow(data);
                                        }
                                    }

                                }
                            });
                        }
                    </script>

                    <script type="text/javascript">
                        function showprofit() {
                            mini.open({
                                url: "/index.php?m=&c=SapSupplier&a=showprofit&item_id="+<?php echo $_REQUEST['id']; ?>,
                            title: "毛利表",
                                width: 800,
                                height: 300,
                                ondestroy: function (action) {
                                if (action == "ok") {
                                    var iframe = this.getIFrameEl();
                                    var data = iframe.contentWindow.GetData();
                                    data = mini.clone(data);    //必须
                                    if (data) {
                                        if (checkItems(data.item_id)) {
                                            mini.alert(data.item_name + '已存在列表中');
                                            return;
                                        }
                                        var ndata = [];
                                        ndata.item_name = data.item_name;
                                        ndata.sap_code = data.sap_code;
                                        ndata.logo = data.logo;
                                        ndata.color = data.color;
                                        ndata.weight = data.weight;
                                        grid2.addRow(data);
                                    }
                                }

                            }
                        });
                        }
                    </script>

                    <!--展示品类 JS 相关 Beginning-->
                    <script type="text/javascript">
                        mini.parse();
                        var tree = mini.get("tree1");
                        tree.selectNode("{$data.category_code}");
                        tree.expandPath("{$data.category_code}");

                        //--------------------------------
                        function onBeforeNodeSelect(e) {

                            var tree = e.sender;
                            var node = e.node;
                            //alert(node.is3C);
                            var is3C = mini.get("is_3c");
                            if (node.is3C == '3C')
                            {
                                is3C.setValue('Y');
                            }else{
                                is3C.setValue('N');
                            }
//                            if (tree.hasChildren(node)) {
//                                e.cancel = true;
//                            }
                        }
                    </script>
                    <!--展示品类 JS 相关 Ending-->

                    <if condition=' ($canEdit) '>
                    <br/>
                    <a class='mini-button' onclick="submitForm(1)" >保存</a>
                    <a class='mini-button' onclick="" >取消</a>
                        <!--CloseWindow()-->
                    </if>


                </td>
            </tr>

        </table>
    </div>
    <script type="text/javascript">
        mini.parse();
        function submitForm(tag) {
            //提交表单数据
            var form = new mini.Form("#form1");
            form.validate();
            if (form.isValid() == false) return;

            // save begin
//            if ($(".uploader .tbody").length > 0)  {
//            }
//            else {
//                mini.alert("必须上传相关附件！");
//                return;
//            }

            //确认提示
            mini.confirm("确定修改记录？", "确定？",
                function (action) {
                    if (action == "ok") {

                        var data = form.getData();      //获取表单多个控件的数据
                        data.attachment = jQuery('#add_file_add_file').val();

                        data.brand_id = mini.get('brand-select').getValue();
                        data.brand_name = mini.get('brand-select').getText();

                        var tree = mini.get("tree1");
                        var node = tree.getSelectedNode();
                        data.category_code = node.id;

                        var json = mini.encode(data);   //序列化成JSON
                        $.ajax({
                            url: "/SapSupplier/doitemadd",
                            type: "post",
                            data: {data: json},
                            dataType: 'json',
                            success: function (data) {
					if(data.code>=0){
//						 mini.confirm(data.msg+" 是否清空表单?", "清空",
//						            function (action) {
//						                if (action == "ok") {
//						                     form.reset();
//						                }
//						            }
//					        );

					}else{

					}
                                mini.alert(data.msg);
                                //CloseWindow();
                            }
                        });

                    } else {
                    }
                });

            // save end

        }


        function CloseWindow(action) {

            if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
            else window.close();
            //location.href=document.referrer;
        }



        function onButtonEdit2(e) {
            var btnEdit = this;
            mini.open({
                url:  "/index.php?m=&c=SapSupplier&a=brandselect",
                title: "选择品牌",
                width: 650,
                height: 380,
                ondestroy: function (action) {
                    if (action == "ok") {
                        var iframe = this.getIFrameEl();
                        var data = iframe.contentWindow.GetData();
                        data = mini.clone(data);    //必须
                        if (data) {
                            btnEdit.setValue(data.b_id);
                            btnEdit.setText(data.b_name);
                            checkAndMergeString('');
                        }
                    }

                }
            });

        }


    </script>



    <script>  
        $(function(){  
            $("#group-picture1").change(function(event) {  
                var img=event.target.files;  
                for(var i=0;i<img.length;i++){
                if(!img){  
                    return false;  
                }  
                if(!(img[i].type.indexOf('image')==0 && img[i].type && /\.(?:jpg|png|gif)$/.test(img[i].name)) ){    
                    gritter('图片只能是jpg,gif,png');    
                    return false;    
                }   
                var reader = new FileReader();  
                reader.readAsDataURL(img[i]);  
                reader.onload = function(e){  
                     $.post("/upload.php", {imga:e.target.result},function(ret){    
                        if(ret.img!=''){

                            // check image size beginning
                            image=new Image();
                            image.src=ret.picUrl;
                            image.onload=function() {
                                if(image.width >= 800 && image.height >= 800){

                                    console.log('upload success');
                                    var html = ' <img id="" class="group-picture" width="100px" height="100px" src="'+ret.picUrl+'" alt="物料图" >  '
                                    $('#showimg').append(html);
                                    mini.get('logo-input').setValue( mini.get('logo-input').getValue()+ret.picUrl+',');

                                }
                                else{
                                    alert("图片宽高必须大于等于800px");
                                    return;
                                }
                            }
                            // check image size end

                        }else{    
                            console.log('upload fail');    
                        }    
                    },'json');    
                }  
                }
            });  
        });  
    </script>

    <script>
        $(function(){
            $("#group-picture2").change(function(event) {
                var img=event.target.files;
                for(var i=0;i<img.length;i++){
                    if(!img){
                        return false;
                    }
                    if(!(img[i].type.indexOf('image')==0 && img[i].type && /\.(?:jpg|png|gif)$/.test(img[i].name)) ){
                        gritter('图片只能是jpg,gif,png');
                        return false;
                    }
                    var reader = new FileReader();
                    reader.readAsDataURL(img[i]);
                    reader.onload = function(e){
                        $.post("/upload.php", {imga:e.target.result},function(ret){
                            if(ret.img!=''){

                                // check image size beginning
                                image=new Image();
                                image.src=ret.picUrl;
                                image.onload=function() {

                                    console.log('upload success');
                                    var html = ' <img id="" class="group-picture" width="100px" height="100px" src="'+ret.picUrl+'" alt="物料详情图" >  '
                                    $('#showimgB').append(html);
                                    mini.get('detail_image-input').setValue( mini.get('detail_image-input').getValue()+ret.picUrl+',');

                                }
                                // check image size end

                            }else{
                                console.log('upload fail');
                            }
                        },'json');
                    }
                }
            });
        });
    </script>

    <script type="text/javascript">

        $(document).ready(function() {
            var uploaders = {};
            $('.uploader').each(function() {
                var uploader, $target, $id;
                $target = $(this);
                $id = $target.attr('add_file_id');
                $btn_id = 'btn_' + $id;
                $uploader_id = 'uploader_' + $id;

                settings = {
                    runtimes : 'html5,flash',
                    browse_button : $btn_id, // you can pass in id...
                    container : document.getElementById($uploader_id),
                    url : upload_url,
                    flash_swf_url : app_path + '/Public/Static/plupload/Moxie.swf',
                    filters : {
                        max_file_size : '1000mb'
                    }
                };

                uploader = new plupload.Uploader(settings);
                uploaders[$id] = uploader;

                function FilesAdded(up, files) {

                    for (var i in files) {
                        var str = JSON.stringify(files);

                        if( files[i].id!=null){

                            html = '<li class="tbody" id="' + files[i].id + '">\n';

                            html += '<div class="loading"></div>\n';
                            html += '<div class="data">\n';

                            html += '<span class="del text-center"><a class="link del">删除</a></span>\n';

                            html += '<span class="size text-right">' + plupload.formatSize(files[i].size) + '</span>';
                            html += '<span class="auto autocut">' + files[i].name + '</span>';
                            html += '</li>';
                            html += '</div>\n';

                            $('#uploader_' + $id + ' .file_list').append(html);
                        }
                    }
                    up.start();
                }

                uploader.bind("PostInit", function(up) {
                    if ($(".uploader .tbody").length > 0) {
                        $(".uploader .tbody .loading").css("width", "100%");
                        $(".uploader .thead").show();
                        $(".uploader .tbody").each(function() {
                            id = $(this).attr("filename");
                            filename = $(this).attr("filename");
                            size = $(this).attr("size");
                            file = new plupload.File(id, filename, size);
                            file.status = plupload.DONE;
                            count = uploader.files.length;
                            uploader.files[count] = file;
                            path = 'hhhhhhh';
                        });
                    }
                });

                uploader.init();

                uploader.bind('FilesAdded', FilesAdded);

                uploader.bind("UploadProgress", function(up, file) {
                    $("#" + file.id).find("a.del").hide();
                    $("#" + file.id).find('.loading').css("width", file.percent + "%");
                });

                uploader.bind('FileUploaded', function(up, file, data) {
                    var myObject = eval('(' + data.response + ')');
                    if (myObject.status) {
                        if ($("#add_file_" + $id).length != 0) {
                            $("#add_file_" + $id).val($("#add_file_" + $id).val() + myObject.sid + ";");
                        }
                        $("#" + file.id).attr("add_file", myObject.sid);

                        $new_upload = $("#uploader_" + $id + " .file_list").attr("new_upload");
                        $("#uploader_" + $id + " .file_list").attr("new_upload", $new_upload + myObject.sid + ";");

                        $("#" + file.id).find("a.del").show();
                    } else {
                        ui_alert(myObject.info, function() {
                            $("#" + file.id).remove();
                        });
                    }
                });
            });
        });

        window.onbeforeunload = function(e) {
            e = e || window.event;
            // For IE and Firefox prior to version 4
            $new_upload = $(".file_list").attr("new_upload");
            if ($new_upload !== undefined) {
                if ($new_upload.length) {
                    if (e) {
                        e.returnValue = '上传的附件将被删除，确定退出吗？';
                    }
                    // For Safari
                    return '上传的附件将被删除，确定退出吗？';
                }
            }
        };

        $(document).on("click", ".uploader a.del", function() {
            $obj = $(this).parents("li");
            $uploader = $(this).parents('.uploader');
            ui_confirm("确定要删除吗？", function() {

                $current_del_file = $obj.attr("add_file");
                $(".add_file", $uploader).val($(".add_file", $uploader).val().replace($current_del_file + ";", ""));

                $new_upload = $(".file_list", $uploader).attr("new_upload");
                $(".file_list", $uploader).attr("new_upload", $new_upload.replace($current_del_file + ";", ""));

                $obj.remove();
            });
        });
    </script>

    <script type="text/javascript">

        function checkAndMergeString(item) {

            //alert(item.value);
            //data.brand_id = mini.get('brand-select').getValue();
            //data.brand_name = mini.get('brand-select').getText();

            var shortName = mini.get('item_short_name').getValue();
            var brand = mini.get('brand-select').getText();
            var model = mini.get('model').getValue();
            var specifications = mini.get('specifications').getValue();
            var color = mini.get('color').getValue();
            var mergedString = brand+' '+shortName+' '+model+' '+specifications+' '+color;
            mini.get('item_name').setValue(mergedString);
            //alert(mergedString);

        }

        function cancelimage(item_id,image_id,image_type) {

            //确认提示
            mini.confirm("确定作废图片？", "确定？",
                function (action) {
                    if (action == "ok") {

                        $.ajax({
                            url: "/SapSupplier/cancelimage",
                            type: "post",
                            data: {item_id: item_id, image_id: image_id, image_type: image_type},
                            dataType: 'json',
                            success: function (data) {
                                mini.alert(data.msg);
                            }
                        });


                    } else {

                    }
                }
            );

        }

    </script>

    </body>
    </html>

</block>
<block name="js">
    <script type="text/javascript">
        function save() {
            sendForm("form_data", "{:U('save')}", "{:U('index')}");
        }
    </script>
</block>